﻿namespace Framework.Utility.Helper
{
    public class HttpRetryHelper
    {
        public async Task<string> GetDataWithRetryAsync(int maxRetries = 3)
        {
            int retryCount = 0;
            while (true)
            {
                try
                {
                    var _httpClient = HttpClientFactoryUtil.Instance.CreateClient();
                    HttpResponseMessage response = await _httpClient.GetAsync("data");
                    response.EnsureSuccessStatusCode(); // 确保请求成功
                    return await response.Content.ReadAsStringAsync(); // 返回响应内容
                }
                catch (HttpRequestException)
                {
                    Console.WriteLine($"重试第{retryCount + 1}次");
                    retryCount++;
                    if (retryCount >= maxRetries)
                    {
                        throw; // 超过重试次数后抛出异常
                    }
                }
            }
        }
    }
}
